﻿using DataModel;

namespace HardwareDriver
{
    public class K8055Controller
    {
        public bool Initialize(int deviceAddress = 0)
        {
            bool b = (K8055Driver.OpenDevice(deviceAddress) == deviceAddress);
            return b;
        }

        public K8055Data ReadData()
        {
            int analog1 = 0, analog2 = 0;
            K8055Driver.ReadAllAnalog(ref analog1, ref analog2);
            int allDigital = K8055Driver.ReadAllDigital();

            var data = new K8055Data
            {
                InputByte0 = (byte)allDigital,
                InputByte1 = (byte)analog1,
                InputByte2 = (byte)analog2
            };
            return data;
        }

        public void WriteData(K8055Data value)
        {
            K8055Driver.WriteAllDigital(value.Output);
        }

        public void Close()
        {
            K8055Driver.ClearAllDigital();
            K8055Driver.ClearAllAnalog();
        }
    }
}